import 'package:get/get.dart';
import 'package:yysk_app/net/api/api_url.dart';
import 'package:yysk_app/net/http.dart';
import 'package:yysk_app/model/common_model/dao_page_model.dart';





class DaoListController extends GetxController {
var number = 10.obs;
int pageNum = 1;
int pageSize = 10;
final listDao = RxList<DaoItemModel>([]);

  @override
  void onInit() {
    super.onInit();
    getDaoPageListData();
  }

  @override
  void onClose() {
  
    super.onClose();
  }

  getDaoPageListData({loadMore = false}) {
    if (loadMore) {
      pageNum++;
    } else {
      pageNum = 1;
    }

    try {
      http.netFetch<DaoPageModel>(
        ApiUrl.daoListPage,
        params: {'pageNum': pageNum, 'pageSize': 20},
        method: Method.post,
        success: (result) {
          List<DaoItemModel> items =result.data?.list ?? [];
          if (loadMore && items.isEmpty) {
            pageNum--;
          }
          if (!loadMore) {
            listDao.clear();
          }
          listDao.addAll(items);
          // listDao.addAll(items);
          // listDao.addAll(items);
          // listDao.addAll(items);
          // listDao.addAll(items);
          // listDao.addAll(items);
    
        },
      );
    } catch (e) {
      if (loadMore) {
        pageNum--;
      }
    }
}
  
}

